package com.nuc.wxh.vaccine_appointment.vaccines.controller.admin;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuc.wxh.vaccine_appointment.base.result.R;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.AdminHospital;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.AllVaccine;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.SysUser;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.VaccineAppointment;
import com.nuc.wxh.vaccine_appointment.vaccines.entity.vo.AdminHospitalVo;
import com.nuc.wxh.vaccine_appointment.vaccines.service.SysUserService;
import com.nuc.wxh.vaccine_appointment.vaccines.service.VaccineAppointmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "已注册用户管理")
@CrossOrigin
@RestController
@RequestMapping("/admin/user")
public class AdminUserController {
    @Autowired
    private SysUserService sysUserService;
    @Autowired
    private VaccineAppointmentService vaccineAppointmentService;

    @ApiOperation("分页查询已注册列表")
    @GetMapping("list/{page}/{limit}")
    public R listPage(@ApiParam(value = "当前页码", required = true) @PathVariable Long page,
                      @ApiParam(value = "每页记录数", required = true) @PathVariable Long limit) {
        Page<SysUser> pageParam = new Page<>(page, limit);
        Page<SysUser> SysUserPage=sysUserService.selectPage(pageParam);
        List<SysUser> records = SysUserPage.getRecords();
        long total = SysUserPage.getTotal();
        return R.ok().data("total", total).data("rows", records);
    }

    @ApiOperation("分页查询疫苗预约")
    @GetMapping("listAppointment/{page}/{limit}")
    public R listPage(@ApiParam(value = "当前页码", required = true) @PathVariable Long page,
                      @ApiParam(value = "每页记录数", required = true) @PathVariable Long limit,
                      @ApiParam(value = "查询对象条件")VaccineAppointment vaccineAppointment) {
        Page<VaccineAppointment> pageParam = new Page<>(page, limit);
        Page<VaccineAppointment> vaccineAppointmentPage=vaccineAppointmentService.selectPage(pageParam, vaccineAppointment);
        List<VaccineAppointment> records = vaccineAppointmentPage.getRecords();
        long total = vaccineAppointmentPage.getTotal();
        return R.ok().data("total", total).data("rows", records);
    }

    @ApiOperation("根据id获取疫苗信息")
    @GetMapping("get/{id}")
    public R getById(@ApiParam(value = "疫苗ID", required = true) @PathVariable String id) {
        VaccineAppointment vaccine = vaccineAppointmentService.getById(id);
        if (vaccine != null) {
            return R.ok().data("item", vaccine);
        } else {
            return R.error().message("数据不存在");
        }
    }


    @ApiOperation("医院修改")
    @PutMapping("update")
    public R updateById(@ApiParam(value = "医院对象", required = true) @RequestBody VaccineAppointment vaccineAppointment) {
        boolean result = vaccineAppointmentService.updateById(vaccineAppointment);
        if (result) {
            return R.ok().message("修改成功");
        } else {
            return R.error().message("修改失败");
        }
    }



}
